using System.Collections;
using System.Collections.Generic;
using PureStateMachine;
using UnityEngine;

// Choose hero
public class TSBattle : PState
{
    public TSBattle(PStateBrain brain) : base(brain)
    {
    }

    public override string Name => "Battle";

    public override void StateInit()
    {
        ;
    }

    public override void StateStart()
    {
        foreach (GridNode node in GridManager.instance.grids)
        {
            node.Pawn?.OnStart();
        }
        GridManager.instance.OnBattleStart();
        Blackboard.GetData<DeckMove>("DeckMove").MoveDown();
    }

    public override void StateUpdate()
    {
        // TransferTo("Choose");

        // TransferTo("End");
    }

    public override void StateEnd()
    {
        Blackboard.GetData<DeckMove>("DeckMove").MoveUp();
    }

    /// <summary>
    /// 3.状态机检查战斗结束
    /// </summary>
    public void CheckIfBattleEnd()
    {
        if (_brain.CurrentState != this)
            return;

        (bool ifEnd, bool ifVictory) = GridManager.instance.CheckIfEndBattle();
        // 如果结束 转状态
        if (ifEnd)
        {
            GridManager.instance.OnBattleEnd();
            if (ifVictory)
                TransferTo("Choose");
            else
                TransferTo("End");
        }
    }
}
